package com.niuwa.p2p.service.impl.business;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.dao.business.LoanClaimDao;
import com.niuwa.p2p.entity.business.LoanClaimLog;
import com.niuwa.p2p.service.business.ILoanClaimInnerService;
import com.niuwa.p2p.service.business.LoanClaimLogService;
import com.niuwa.p2p.service.productTemplate.ProductService;

@Service
public class LoanClaimInnerServiceImpl implements ILoanClaimInnerService{
	
	@Autowired
	private LoanClaimDao loanClaimDao;

	
	@Autowired
	private LoanClaimLogService loanClaimLogService;

	@Autowired
	private ProductService productService;
	
	
	@Override
	public int batchInnerUpdateDirectPublish(Map<String,Object> paramMap,String projectNo,LoanClaimLog logBean) throws Exception {
		paramMap.put("projectNo", projectNo);
		int ct= loanClaimDao.updateReleaseStatusAndProjectTo(paramMap);
		if(ct>0){//存在有效的项目才做后续动作
			//生成一个直投产品
			productService.addDirectProduct(projectNo);
			//记操作日志
			logBean.setProjectCode(projectNo);
			loanClaimLogService.insertLoanClaimLog(logBean);
		}
		return ct;
	}

	@Override
	public int batchInnerUpdateBackMatch(Map<String,Object> paramMap,String projectNo,LoanClaimLog logBean) throws Exception {
		paramMap.put("projectNo", projectNo);
		int ct= loanClaimDao.updateReleaseStatusAndProjectTo(paramMap);
		if(ct>0){//存在有效的项目才做后续动作
			logBean.setProjectCode(projectNo);
			loanClaimLogService.insertLoanClaimLog(logBean);
		}
		return ct;
	}

	@Override
	public int batchInnerUpdateRejectProject(Map<String,Object> paramMap,String projectNo,LoanClaimLog logBean) throws Exception {
		paramMap.put("projectNo", projectNo);
		int ct= loanClaimDao.updateReleaseStatusAndProjectTo(paramMap);
		if(ct>0){//存在有效的项目才做后续动作
			logBean.setProjectCode(projectNo);
			loanClaimLogService.insertLoanClaimLog(logBean);
		}
		return ct;
	}
	
}
